﻿using System;
using Microsoft.Extensions.Logging;

namespace Utils.NLogHelper;

public class NLogHelper : INlogHelper
{
    private ILogger<NLogHelper> _logger { get; set; }

    public NLogHelper(ILogger<NLogHelper> logger)
    {
        _logger = logger;
    }
    public void Log(string message)
    {
        _logger.LogWarning("{message}", message);
    }
    private static LogMessage? LogMessage { get; set; }
    public void LogError(Exception exception)
    {
        LogMessage = new LogMessage
        {
            LogInfo = exception.InnerException != null ? exception.InnerException.Message : exception.Message,
            StackTrace = exception.StackTrace ?? "null",
            OperationTime =DateTime.Now
        };
        var res = LogFormat.ErrorFormat(LogMessage);
        _logger.LogError(message: res!);
    }
}